<?php
namespace Home\Controller;
use Think\Controller;
header("Content-type: text/html; charset=utf-8"); 
class InfoController extends Controller {
    public function allInfo(){

        $m = M("cate");
        $cateList1 = $m->where('fid = 1')->select();
        $cateList2 = $m->where('fid = 2')->select();
        $this->assign('cateList1',$cateList1);
        $this->assign('cateList2',$cateList2);

    	$m = M("cate");
        $this->assign('currenttype',I('request.type','1'));
    	$map['fid'] = I('request.type','1');
        $cateList = $m->where($map)->select();
        $this->assign('cateList',$cateList);
    	if(I('request.ctype','0')!='0'){
    		$map['typeid'] = I('request.ctype','0');
            $this->assign('currentctype',I('request.ctype','0'));
    	}
        $count=$m->field('ip_info.id,picurl,ip_name,cate_name')->where($map)->join('ip_info ON ip_cate.id = ip_info.typeid')->count();
        $Page = new \Think\Page($count,5);
        $show = $Page->show();
        $list = $m->field('ip_info.id,picurl,ip_name,cate_name')->where($map)->join('ip_info ON ip_cate.id = ip_info.typeid')->limit($Page->firstRow.','.$Page->listRows)->select();
    	$this->assign("infoList",$list);
        $this->assign('page',$show);
        
       	$this->display();
    }

    public function showInfo(){
        $m = M("cate");
        $cateList1 = $m->where('fid = 1')->select();
        $cateList2 = $m->where('fid = 2')->select();
        $this->assign('cateList1',$cateList1);
        $this->assign('cateList2',$cateList2);
        $m = M("info");
        $map['ip_info.id'] = $_GET['id'];
        $info = $m->field('ip_info.id,picurl,ip_name,intro,phone,ctime,price,cate_name')->where($map)->join('ip_cate ON ip_info.typeid = ip_cate.id')->select();
        // var_dump($info);
        $this->assign('info',$info);
        $this->display();
    }

    public function searchInfo(){
        $m = M("cate");
        $cateList1 = $m->where('fid = 1')->select();
        $cateList2 = $m->where('fid = 2')->select();
        $this->assign('cateList1',$cateList1);
        $this->assign('cateList2',$cateList2);
        // echo $_POST['keyword'];

        $m = M("info");
        $map['ip_name'] = array('like','%'.$_GET['keyword'].'%');
        $count= $m->field('ip_info.id,picurl,ip_name,cate_name')->where($map)->join('ip_cate ON ip_info.typeid = ip_cate.id')->count();
        $Page = new \Think\Page($count,8);
        $show = $Page->show();
        $info = $m->field('ip_info.id,picurl,ip_name,cate_name')->where($map)->join('ip_cate ON ip_info.typeid = ip_cate.id')->limit($Page->firstRow.','.$Page->listRows)->select();
        $this->assign("count",$count);
        $this->assign("keyword",$_GET['keyword']);
        $this->assign("infoList",$info);
        $this->assign('page',$show);

        $this->display();
    }
}